package com.csi.bumblebee.controller;


import com.csi.bumblebee.domain.dictionary.MyLocation;
import com.csi.bumblebee.domain.util.MyResult;
import com.csi.bumblebee.domain.util.StateCode;
import com.csi.bumblebee.service.MyLocationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 地理位置字典表
 * @author wdl
 */
@RestController
@RequestMapping("/location")
public class MyLocationController {

    @Autowired
    private MyLocationService myLocationService;

    /**
     * 查询一级城市分类列表
     */
    @GetMapping("/one")
    public MyResult<List<MyLocation>> listLocationOne(){

        List<MyLocation> myLocations = this.myLocationService.listLocationOne();

        if (myLocations!=null && myLocations.size()>0){
            return new MyResult<>(myLocations,StateCode.FIND_SUCCESS,"查询一级城市列表成功");
        }
        return new MyResult<>(null,StateCode.FIND_SUCCESS,"查询一级城市列表失败");

    }


    /**
     * 查询二级城市分类列表
     */
    @GetMapping("/two")
    public MyResult<List<MyLocation>> listLocationTwo(){

        List<MyLocation> myLocations = this.myLocationService.listLocationTwo();

        if (myLocations!=null && myLocations.size()>0){
            return new MyResult<>(myLocations,StateCode.FIND_SUCCESS,"查询二级城市列表成功");
        }
        return new MyResult<>(null,StateCode.FIND_SUCCESS,"查询二级城市列表失败");

    }

    /**
     * 查询一级城市下的二级城市分类列表
     */
    @GetMapping("/{id}")
    public MyResult<List<MyLocation>> listLocationSon(@PathVariable("id") String id){
        System.out.println("id============"+id);
        List<MyLocation> myLocations = this.myLocationService.listLocationSon(id);

        if (myLocations!=null && myLocations.size()>0){
            System.out.println("查询一级城下的二级城城区成功");
            return new MyResult<>(myLocations,StateCode.FIND_SUCCESS,"查询一级城下的二级城城区成功");

        }
        return new MyResult<>(null,StateCode.FIND_FAILURE,"查询一级城下的二级城城区失败");

    }

    /**
     * 查询全部城市列表
     */
    @GetMapping("/list/tree")
    public MyResult<List<MyLocation>> listLocationTree(){
        List<MyLocation> myLocations = this.myLocationService.listLocationTree();

        if (myLocations!=null && myLocations.size()>0){
            return new MyResult<>(myLocations,StateCode.FIND_SUCCESS,"查询全部城市成功");

        }
        return new MyResult<>(null,StateCode.FIND_FAILURE,"查询全部城市失败");

    }


}
